﻿SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[irm_ApplicationQueueStatus](
	[Id] [int] NOT NULL,
	[Description] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_QueueStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[irm_ApplicationQueue](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Entity] [nvarchar](2000) NOT NULL,
	[EntityId] [int] NOT NULL,
	[Action] [int] NOT NULL,
	[Data] [varchar](max) NULL,
	[Topic] [varchar](2000) NOT NULL,
	[QueueStatusId] [int] NOT NULL,
	[RescheduleUntil] [smalldatetime] NULL,
	[Error] [varchar](max) NULL,
	[CreatedBy] [nvarchar](200) NOT NULL,
	[Created] [smalldatetime] NOT NULL,
	[Changed] [smalldatetime] NOT NULL,
 CONSTRAINT [PK_Queue] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING ON
GO

ALTER TABLE [dbo].[irm_ApplicationQueue]  WITH CHECK ADD  CONSTRAINT [FK_Queue_QueueStatus] FOREIGN KEY([QueueStatusId])
REFERENCES [dbo].[irm_ApplicationQueueStatus] ([Id])
GO

ALTER TABLE [dbo].[irm_ApplicationQueue] CHECK CONSTRAINT [FK_Queue_QueueStatus]
GO

ALTER TABLE [dbo].[irm_ApplicationQueue] ADD  CONSTRAINT [DF_Queue_Created]  DEFAULT (getdate()) FOR [Created]
GO

ALTER TABLE [dbo].[irm_ApplicationQueue] ADD  CONSTRAINT [DF_Queue_Changed]  DEFAULT (getdate()) FOR [Changed]
GO

INSERT INTO [dbo].[irm_ApplicationQueueStatus]
([Id], [Description])
VALUES
(1, 'Added')

INSERT INTO [dbo].[irm_ApplicationQueueStatus]
([Id], [Description])
VALUES
(2, 'Processing')

INSERT INTO [dbo].[irm_ApplicationQueueStatus]
([Id], [Description])
VALUES
(3, 'Processed')

INSERT INTO [dbo].[irm_ApplicationQueueStatus]
([Id], [Description])
VALUES
(4, 'Rescheduled')

INSERT INTO [dbo].[irm_ApplicationQueueStatus]
([Id], [Description])
VALUES
(5, 'Error')

GO